% This file generates Figure D2 and D3 presented in Appendix D of the
% paper. They perform an analysis of the senstitivity of the SLP results to
% different values of r and lambda. The file uses
% 'FIGs_D2_D3_Monte_Carlo_Loop.m'. 

clear; close all; clc;
%% 

% Options for S/LP
H           =   9;                      % Number of horizons.
lambda      =   100;                    % Value of penalty.
                
%% Loop over different rs. 

rs              =   [2; 3; 4];            % (r-1) = order of the limit polynomial 
                                        % (so r=3 implies the IR is shrunk 
                                        % towards a quadratic polynomial).
%Preallocating.
IRFav           =   zeros(3,H);
IRF20           =   zeros(3,H);
IRF200          =   zeros(3,H);
IRF650          =   zeros(3,H);

for ijx = 1:length(rs)
    r               =   rs(ijx);
    run FIGs_D2_D3_Monte_Carlo_Loop.m
    IRFav(ijx,:)     =   irfslpm;
    IRF20(ijx,:)     =   irfslp(20,:);
    IRF200(ijx,:)    =   irfslp(200,:);
    IRF650(ijx,:)    =   irfslp(650,:);
end

%% Loop over different lambdas. 

r               =   3;
lambdas         =   [1; 100; 10000];
%Preallocating.
IRFFav          =   zeros(3,H);
IRFF20          =   zeros(3,H);
IRFF200         =   zeros(3,H);
IRFF650         =   zeros(3,H);

for ijx = 1:length(rs)
    lambda          =   lambdas(ijx);
    run FIGs_D2_D3_Monte_Carlo_Loop.m
    IRFFav(ijx,:)    =   irfslpm;
    IRFF20(ijx,:)    =   irfslp(20,:);
    IRFF200(ijx,:)   =   irfslp(200,:);
    IRFF650(ijx,:)   =   irfslp(650,:);
end

%% Creating figure.

t = 0:H-1;

figure
subplot(2,2,1)
plot(t,IRF(2,:),'-k',t,IRFav(1,:),'--k',t,IRFav(2,:),':k',t,IRFav(3,:),'-b','Linewidth',1.5)
title('Average','Interpreter','latex','fontSize',14);
h = legend('True','$r = 2$','$r = 3$','$r = 4$','Location','SouthEast');
set(h,'Interpreter','latex');
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on
subplot(2,2,2)
plot(t,IRF(2,:),'-k',t,IRF20(1,:),'--k',t,IRF20(2,:),':k',t,IRF20(3,:),'-b','Linewidth',1.5);
title('Draw 20','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on
subplot(2,2,3)
plot(t,IRF(2,:),'-k',t,IRF200(1,:),'--k',t,IRF200(2,:),':k',t,IRF200(3,:),'-b','Linewidth',1.5)
title('Draw 200','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on
subplot(2,2,4)
plot(t,IRF(2,:),'-k',t,IRF650(1,:),'--k',t,IRF650(2,:),':k',t,IRF650(3,:),'-b','Linewidth',1.5)
title('Draw 650','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on

figure
subplot(2,2,1)
plot(t,IRF(2,:),'-k',t,IRFFav(1,:),'--k',t,IRFFav(2,:),':k',t,IRFFav(3,:),'-b','Linewidth',1.5)
title('Average','Interpreter','latex','fontSize',14);
h = legend('True','$\lambda = 1$','$\lambda = 100$','$\lambda = 10000$','Location','SouthEast');
set(h,'Interpreter','latex');
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on
subplot(2,2,2)
plot(t,IRF(2,:),'-k',t,IRFF20(1,:),'--k',t,IRFF20(2,:),':k',t,IRFF20(3,:),'-b','Linewidth',1.5)
title('Draw 20','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);grid on
subplot(2,2,3)
plot(t,IRF(2,:),'-k',t,IRFF200(1,:),'--k',t,IRFF200(2,:),':k',t,IRFF200(3,:),'-b','Linewidth',1.5)
title('Draw 200','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on
subplot(2,2,4)
plot(t,IRF(2,:),'-k',t,IRFF650(1,:),'--k',t,IRFF650(2,:),':k',t,IRFF650(3,:),'-b','Linewidth',1.5)
title('Draw 650','Interpreter','latex','fontSize',14);
xlabel('Horizon','Interpreter','latex','fontSize',12);
grid on

    